﻿using System;
using Plugins.Interfaces;
using Plugins.Serializer;
using System.Xml.Serialization;
using System.Xml.Schema;
using System.Xml;

namespace MathML
{
    [Serializable]
    public class Math : IXmlSerializable
    {
        private static IPluginRuntimeFormatter Formatter = new XmlFormatter();
        private static IPluginStringSerializer<Math> XmlSerializer = new PluginUnicodeStringSerializer<Math>();

        public class XmlFormatter : PluginTypeSerializer<Math>
        {
            public override void AddOverrides(IPluginTypeFormatter formatter)
            {
                base.AddRoot(formatter, new XmlRootAttribute() { ElementName="math", Namespace = "http://www.w3.org/1998/Math/MathML" });
                base.AddNamespace(formatter, false);
                base.WriterSettings.OmitXmlDeclaration = true;
            }
        }

        public static string Serialize(Math m)
        {
            return XmlSerializer.Serialize(m, Formatter);
        }

        #region IXmlSerializable Members

        public XmlSchema GetSchema()
        {
            return null;
        }

        public void ReadXml(XmlReader reader)
        {
            if (reader.MoveToAttribute("ns"))
            {
                if (reader.ReadAttributeValue())
                {
                    string s = reader.Value;
                }
            }
        }

        public void WriteXml(XmlWriter writer)
        {
            writer.WriteAttributeString("ns", "http://www.openmath.org/OpenMath");
        }

        #endregion
    }
}
